﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sectors;
using Neat.Mathematics;

namespace SectorsDesigner
{
    public partial class WallPropertiesForm : Form
    {
        Wall wall; SectorsMapMakerControl Designer;
        public WallPropertiesForm(Wall w, SectorsMapMakerControl m)
        {
            InitializeComponent();
            Designer = m;
            wall = w;
            Load(wall);
        }

        private void SaveButton_Click(object sender, EventArgs e)
        {
            Save(wall);
        }

        public void Load(Wall w)
        {
            NameBox.Text = w.Name;
            TextureBox.Text = w.Texture;
            TextureBBox.Text = w.TextureB;
            TextureLBox.Text = w.TextureL;
            TextureUBox.Text = w.TextureU;
            TextureUVBox.Text = GeometryHelper.Vector2String(w.TextureUV);
            TextureBUVBox.Text = GeometryHelper.Vector2String(w.TextureBUV);
            TextureLUVBox.Text = GeometryHelper.Vector2String(w.TextureLUV);
            TextureUUVBox.Text = GeometryHelper.Vector2String(w.TextureUUV);
            WallTypeBox.Text = ((int)w.WallType).ToString();
        }

        public void Save(Wall w)
        {
            w.Name = NameBox.Text;
            w.Texture = TextureBox.Text;
            w.TextureB = TextureBBox.Text;
            w.TextureL = TextureLBox.Text;
            w.TextureU = TextureUBox.Text;
            w.TextureUV = GeometryHelper.String2Vector(TextureUVBox.Text);
            w.TextureBUV = GeometryHelper.String2Vector(TextureBUVBox.Text);
            w.TextureLUV = GeometryHelper.String2Vector(TextureLUVBox.Text);
            w.TextureUUV = GeometryHelper.String2Vector(TextureUUVBox.Text);
            w.WallType = (Sectors.Wall.WallTypes)(int.Parse(WallTypeBox.Text));
        }

        private void TextureBtn_Click(object sender, EventArgs e)
        {
            UseTextureChooser(TextureBox);
        }

        private void TextureBBtn_Click(object sender, EventArgs e)
        {
            UseTextureChooser(TextureBBox);
        }

        private void TextureLBtn_Click(object sender, EventArgs e)
        {
            UseTextureChooser(TextureLBox);
        }

        private void TextureUBtn_Click(object sender, EventArgs e)
        {
            UseTextureChooser(TextureUBox);
        }

        void UseTextureChooser(TextBox t)
        {
            TextureChooserDialog d = new TextureChooserDialog(Designer);
            if (d.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
            t.Text = d.TextureNameBox.Text.Trim().ToLower();
        }
    }
}
